package sysAuth

import initConfig.SysInitData

/*
区域、组织机构：与数据权限有关，将来定义的数据权限需要关联
 */
class SysOrganization {

    String orgNo;
    String name;
    String state = "1";
    Long parentId;
    String marks;//备注
    int orderNum = 0;//展示顺序
    String creator ;//操作人
    String updater;//最近一次更新人
    Date dateCreated;
    Date lastUpdated;

    static constraints = {
        orgNo(nullable: false, blank: false)
        name(nullable: false)
        state(nullable: false, blank: false)
        orderNum(nullable: true, blank: false)
        marks(nullable: true, blank: false)
        creator(nullable: false, blank: false)
        updater(nullable: true, blank: false)
        parentId(nullable: true, blank: false)
    }
    static mapping = {
        version false
    }

    static init(){
        if(SysOrganization.count() ==0){
            def root = new SysOrganization (orgNo: "root",name: "大中华集团",creator: SysInitData.SYS_ADMIN)
            root.save(flush: true)
            def child = new SysOrganization(orgNo: 'org1',name: "陕西分公司",creator: SysInitData.SYS_ADMIN,parentId: root.id)
            child.save(flush: true)
            child = new SysOrganization(orgNo: 'org2',name: "上海办事处",creator: SysInitData.SYS_ADMIN,parentId: root.id)
            child.save(flush: true)
            child = new SysOrganization(orgNo: 'org3',name: "华东大区",creator: SysInitData.SYS_ADMIN,parentId: root.id)
            child.save(flush: true)
        }

    }
}
